﻿using System;
using System.ComponentModel;
using VNet.VisiSuite.Common.Resource;

namespace VNet.VisiSuite.VisiAdmin.Models
{
    public class ScheduleModel : ComparableBaseModel<ScheduleModel>, IDataErrorInfo
    {


        private int _scheduleId;
        public int ScheduleId
        {
            get { return _scheduleId; }
            set
            {
                _scheduleId = value;
                OnPropertyChanged("ScheduleId");
            }
        }

        private int _areaId;
        public int AreaId
        {
            get { return _areaId; }
            set
            {
                _areaId = value;
                OnPropertyChanged("AreaId");
            }
        }



        private string _subject;

        [Category("Properties")]
        [DisplayName("Subject")]
        [Description("Scheduler Subject.")]
        public string Subject
        {
            get { return _subject; }
            set
            {
                _subject = value;
                OnPropertyChanged("Subject", true);
                OnPropertyChanged("SubjectWithLink", true);
            }
        }

        public int _reasonCodeId;
        [Category("Properties")]
        [DisplayName("Reason Code")]
        [Description("Reason Code")]
        public int ReasonCodeId
        {
            get { return _reasonCodeId; }
            set
            {
                _reasonCodeId = value;
                OnPropertyChanged("ReasonCodeId", true);
              
            }
        }

        private DateTime _startTime;
        [Category("Properties")]
        [DisplayName("Start Time")]
        [Description("Start Time")]
        public DateTime StartTime
        {
            get { return _startTime; }
            set
            {
                _startTime = value;
                OnPropertyChanged("StartTime", true);
            }
        }


        private DateTime _endTime;
        [Category("Properties")]
        [DisplayName("End Time")]
        [Description("End Time")]
        public DateTime EndTime
        {
            get { return _endTime; }
            set
            {
                _endTime = value;
                OnPropertyChanged("EndTime", true);
            }
        }

        private int? _scheduleRepeatId;
        [Category("Properties")]
        [DisplayName("Recurrence")]
        [Description("Recurrence")]
        public int? ScheduleRepeatId
        {
            get { return _scheduleRepeatId; }
            set
            {
                _scheduleRepeatId = value;
                OnPropertyChanged("ScheduleRepeatID", true);
            }
        }

        private string _createdBy;
        [Category("Update History")]
        [DisplayName("Created By")]
        [Description("Created By")]
        public string CreatedBy
        {
            get { return _createdBy; }
            set
            {
                _createdBy = value;
                OnPropertyChanged("CreatedBy", true);
            }
        }


        private string _createdDate;
        [Category("Update History")]
        [DisplayName("Created On")]
        [Description("Created On")]
        public string CreatedDate
        {
            get { return _createdDate; }
            set
            {
                _createdDate = value;
                OnPropertyChanged("CreatedDate", true);
            }
        }


        private string _lastUpdatedBy;
        [Category("Update History")]
        [DisplayName("Update By")]
        [Description("Update By")]
        public string LastUpdatedBy
        {
            get { return _lastUpdatedBy; }
            set
            {
                _lastUpdatedBy = value;
                OnPropertyChanged("LastUpdatedBy", true);
            }
        }

        private string _lastUpdatedDate;
        [Category("Update History")]
        [DisplayName("Update On")]
        [Description("Update On")]
        public string LastUpdatedDate
        {
            get { return _lastUpdatedDate; }
            set
            {
                _lastUpdatedDate = value;
                OnPropertyChanged("LastUpdatedDate", true);
            }
        }


        private DateTime _timeStamp;
        public DateTime TimeStamp
        {
            get { return _timeStamp; }
            set
            {
                _timeStamp = value;
                OnPropertyChanged("TimeStamp", true);
            }
        }

        public string this[string columnName]
        {
            get
            {
                if (!ShouldValidate)
                    return string.Empty;

                if (columnName == "Subject" && string.IsNullOrWhiteSpace(Subject))
                    return ValidationMessages.DescriptionRequired;

                return string.Empty;
            }
        }

        public string Error { get { return string.Empty; } }


        #region Override Equals methods
        public bool Equals(ScheduleModel other)
        {

            if (ReferenceEquals(null, other))
                return false;
            if (ReferenceEquals(this, other))
                return true;

            return
                ScheduleId == other.ScheduleId
                && AreaId == other.AreaId
                && ReasonCodeId == other.ReasonCodeId
                && string.Equals(Subject, other.Subject)
                && StartTime  == other.StartTime 
                && EndTime == other.EndTime 
                && (ScheduleRepeatId ?? 0) == (other.ScheduleRepeatId ?? 0)
                && TimeStamp == other.TimeStamp;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
                return false;
            if (ReferenceEquals(this, obj))
                return true;
            if (obj.GetType() != this.GetType())
                return false;
            return Equals((ScheduleModel)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return ScheduleId.GetHashCode();
            }
        }
        #endregion


    }
}
